using System;
using System.Collections.Generic;
using System.Text;
using VSSDKAssist.Assets.Actions.Base;
using VSSDKAssist.Assets.Actions.General;
using System.IO;
using System.Globalization;
using VSSDKAssist.Assets.Enums;
using Microsoft.Practices.RecipeFramework;
using VSSDKAssist.Recipes.Common.Helpers;

namespace VSSDKAssist.Recipes.RefreshVSPackageRegistration
{
	/// <summary>
	/// Action thats refreshes the VS
	/// </summary>
	public class RefreshVSPackageRegistrationAction : ActionBase
	{
		private VSHive vsHive = VSHive.Experimental;

		/// <summary>
		/// Gets or sets the vs hive.
		/// </summary>
		/// <value>The vs hive.</value>
		[Input(Required = false)]
		public VSHive VSHive
		{
			get { return vsHive; }
			set { vsHive = value; }
		}

		/// <summary>
		/// Called when [execute].
		/// </summary>
		protected override void OnExecute()
		{
			using(ExecuteProcessAction executeProcessAction = new ExecuteProcessAction())
			{
				executeProcessAction.Site = this.Site;
				executeProcessAction.FileName =
					Path.Combine(CommonHelper.GetVSInstallPath(), Constants.DevEnv);

				switch(this.vsHive)
				{
					case VSHive.Standard:
						executeProcessAction.Arguments = @"/Setup";
						break;
					case VSHive.Experimental:
						executeProcessAction.Arguments = @"/rootSuffix Exp /Setup";
						break;
					default:
						executeProcessAction.Arguments = @"/rootSuffix Exp /Setup";
						break;
				}

				executeProcessAction.Execute();
			}
		}
	}
}